package com.wanxi.controller;

import com.wanxi.model.ClothingStyleModel;
import com.wanxi.model.ResultModel;
import com.wanxi.service.ClothingStyleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 杨金乾
 */
@Controller
@CrossOrigin(origins = "*")
public class ClothingStyleController{
    @Autowired
    private  ClothingStyleService clothingStyleService;

    @Autowired
    SendMessageController sendMessageController;
    private String table="产品样式";
    @RequestMapping("/back/clothingstyle/delete")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected  ResultModel clothingstyleDelete(ClothingStyleModel model) throws  IOException {

        ResultModel resultModel = clothingStyleService.delete(model);
        sendMessageController.deleteUserMessages(table);
        return resultModel;
    }

    @RequestMapping("/back/clothingstyle/add")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel clothingstyleAdd(ClothingStyleModel model) throws  IOException {

        ResultModel resultModel =clothingStyleService.add(model);
        sendMessageController.addUserMessages(table);

        return resultModel;
    }

    @RequestMapping("/back/clothingstyle/findAll")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel clothingstyleFindAll(ClothingStyleModel model) throws  IOException {

        ResultModel resultModel = clothingStyleService.findAll(model);
        sendMessageController.findAllUserMessages(table);
        return resultModel;
    }

    @RequestMapping("/back/clothingstyle/findById")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel clothingstyleFindById(ClothingStyleModel model) throws  IOException {

        ResultModel resultModel=clothingStyleService.findById(model);
        sendMessageController.findByIdUserMessages(table);

        return resultModel;
    }

    @RequestMapping("/back/clothingstyle/enable")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel clothingstyleUpdateEnable(ClothingStyleModel model) throws  IOException {

        ResultModel resultModel = clothingStyleService.enable(model);
        sendMessageController.updateEnableMessages(table);
        return resultModel;
    }

    @RequestMapping("/back/clothingstyle/isShow")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel clothingstyleUpdateIsShow(ClothingStyleModel model) throws  IOException {

        ResultModel resultModel = clothingStyleService.isShow(model);
        sendMessageController.updateIsShowMessages(table);

        return resultModel;
    }

    @RequestMapping("/back/clothingstyle/update")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel clothingstyleUpdate(ClothingStyleModel model) throws  IOException {

        ResultModel resultModel = clothingStyleService.update(model);
        sendMessageController.updateMessages(table);

        return resultModel;
    }
}
